import Vue from 'vue';
import VueRouter from 'vue-router';
import routes from './routes';

Vue.use(VueRouter);



//储存原来的push和replace跳转方法
let originPush=VueRouter.prototype.push;
let originReplace=VueRouter.prototype.replace;
//重写push和replace跳转方法
VueRouter.prototype.push=function(location,resolve,reject){
    if(resolve&&reject){
        //call和apply都是传参的方法，call是逗号分隔，apply是数组
        originPush.call(this,location,resolve.reject)
    }else{
        originPush.call(this,location,()=>{},()=>{})
    }
}
VueRouter.prototype.replace=function(location,resolve,reject){
    if(resolve&&reject){
        //call和apply都是传参的方法，call是逗号分隔，apply是数组
        originReplace.call(this,location,resolve.reject)
    }else{
        originReplace.call(this,location,()=>{},()=>{})
    }
}

export default new VueRouter({
    routes,
    scrollBehavior(){
        return{y:0}
    }
})
